/**
 * 分红流水
 * Created by KY on 2017/4/18.
 */

define(['ldfw/core','art','text!tpl/dividend/detail.tpl',
        'comps/ajax', 'ldfw/utils/format','ldfw/helper/formatHelper'],
    function (LDFW,artTemplate ,tpl, ajax) {
        const rowTpl =
            `{{if $data}}{{each $data transaction}}
            <div class="weui-form-preview">
                    <div class="weui-form-preview__hd">
                        <div class="weui-form-preview__item">
                            <label class="weui-form-preview__label">分红金额</label>
                            <em class="weui-form-preview__value">¥<%=$imports.format('number','$0.00',transaction.divi_amt)%></em>
                        </div>
                    </div>
                    <div class="weui-form-preview__bd">
                        <div class="weui-form-preview__item">
                            <label class="weui-form-preview__label">分红日期</label>
                            <span class="weui-form-preview__value"><%=$imports.format('date','yyyy-MM-dd',transaction.rights_regdate)%></span>
                        </div>
                        <div class="weui-form-preview__item">
                            <label class="weui-form-preview__label">分红产品</label>
                            <span class="weui-form-preview__value">{{transaction.pd_name}}</span>
                        </div>
                        <div class="weui-form-preview__item">
                            <label class="weui-form-preview__label">分红份额</label>
                            <span class="weui-form-preview__value"><%=$imports.format('number','$0.00',transaction.pd_share)%></span>
                        </div>
                        <div class="weui-form-preview__item">
                            <label class="weui-form-preview__label">实际收益</label>
                            <span class="weui-form-preview__value">¥<%=$imports.format('number','$0.00',transaction.real_divi_amt)%></span>
                        </div>
                    </div>
                </div>
            {{/each}}
            {{else}}
                <div class="weui-loadmore weui-loadmore_line"><span class="weui-loadmore__tips">暂无数据</span></div>
            {{/if}}`
        var View = LDFW.Container.extend({
            tpl: tpl,
            className:'panel detail-panel',
            initialize: function () {
                this.on('shown', function () {
                    this.loadData()
                })
            },
            setProductNo:function(pd_no){
                this.pd_no = pd_no
            },
            loadData: function () {
                const _this = this
                let param = {
                    pd_no: this.pd_no,
                    qry_begin_date: 0,
                    qry_end_date: new Date().format('yyyyMMdd')
                }
                ajax.post('pfL.1.208', param).success(function (resp) {
                    let html = artTemplate.compile(rowTpl)(resp.result)
                    _this.$el.find('.detail-panel_body').html(html)
                })
            }
        })
        return new View()
    })